<template>
  <el-card>
    <el-row>
      <el-col :span="24">
        <div class="search">
          <div class="range">
            <el-date-picker v-model="range" 
            size="large" style="width: 250px;" class="range" type="datetimerange" 
            :start-placeholder="$t('boat.seekTimeStart')" :end-placeholder="$t('boat.seekTimeEnd')"
            format="DD/MM/YYYY HH:mm:ss" value-format="DD/MM/YYYY HH:mm:ss" @change="change" />
          </div>
          <div class="range">
            <el-date-picker v-model="range2" 
            size="large" style="width: 250px;" class="range" type="datetimerange" 
            :start-placeholder="$t('boat.handleTimeStart')" :end-placeholder="$t('boat.handleTimeEnd')"
            format="DD/MM/YYYY HH:mm:ss" value-format="DD/MM/YYYY HH:mm:ss" @change="change2" />
          </div>

          <el-select v-model="query.recordFlag" :placeholder="$t('sys.status')" size="large" class="inpt" filterable clearable>
            <el-option v-for="(item, idx) in status" :key="idx" :label="item" :value="idx + 1" />
          </el-select>
          <el-input v-model="query.consultProduct" size="large" :placeholder="$t('boat.seekBoat')" clearable class="inpt"></el-input>
          <el-input v-model="query.consultantFirstName" size="large" :placeholder="$t('boat.firstName')" clearable class="inpt"></el-input>
          <el-input v-model="query.consultantLastName" size="large" :placeholder="$t('boat.lastName')" clearable class="inpt"></el-input>
          <el-input v-model="query.email" size="large" :placeholder="$t('boat.cusEmail')" clearable class="inpt"></el-input>
          <el-input v-model="query.phoneNumber" size="large" :placeholder="$t('boat.cusPhone')" clearable class="inpt"></el-input>
          <el-input v-model="query.handlePersonnel" size="large" :placeholder="$t('boat.handleMan')" clearable class="inpt"></el-input>
          <el-button size="large" type="primary" @click="search()" v-auth="auths.add">
            {{ $t('operation.search') }}
          </el-button>
        </div>
      </el-col>
    </el-row>
    <el-table border style="margin: 10px 0px" :data="list">
      <el-table-column :label="$t('boat.lasttName')" show-overflow-tooltip prop="consultantLastName"></el-table-column>
      <el-table-column :label="$t('boat.firstName')" show-overflow-tooltip prop="consultantFirstName"></el-table-column>
      <el-table-column :label="$t('boat.cusPhone')" show-overflow-tooltip prop="phoneNumber"></el-table-column>
      <el-table-column :label="$t('boat.cusEmail')" show-overflow-tooltip prop="email"></el-table-column>
      <el-table-column :label="$t('boat.seekInfo')" show-overflow-tooltip prop="consultDepict"></el-table-column>
      <el-table-column :label="$t('boat.seekBoat')" show-overflow-tooltip prop="consultProduct"></el-table-column>
      <el-table-column :label="$t('boat.seekTime')" show-overflow-tooltip prop="consultDate"></el-table-column>
      <el-table-column :label="$t('boat.handleMan')" show-overflow-tooltip prop="handlePersonnel"></el-table-column>
      <el-table-column :label="$t('boat.handleWay')" show-overflow-tooltip prop="handleType"></el-table-column>
      <el-table-column :label="$t('boat.handleTime')" show-overflow-tooltip prop="handleDate"></el-table-column>
      <el-table-column :label="$t('sys.status')" show-overflow-tooltip prop="recordFlag">
        <template #="{ row, $index }">
          {{ status[row.recordFlag - 1] }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('operation.oper')" width="250px" fixed="right">
        <template #="{ row, $index }">
          <el-button
            type="primary"
            size="small"
            icon="Edit"
            v-auth="auths.edit"
            @click="handle(row)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      v-model:current-page="pageNo"
      v-model:page-size="pageSize"
      :page-sizes="[10, 20, 30, 40]"
      :background="true"
      layout="prev, pager, next, jumper,->,sizes,total"
      :total="total"
      @current-change="getPage"
      @size-change="handler"
    />

    <Save ref="save" @callback="getPage()" />
  </el-card>
</template>

<script setup lang="ts">
import { ref, onMounted, reactive } from 'vue'
//引入请求
import { seekGetPage } from '@/api/seek_member/seek'
//引入ts类型
import { ElMessage } from 'element-plus'
import Save from './save.vue'
import { status } from './type'
const auths = {
  add: '/t-vessels-info/add',
  edit: '/t-vessels-info/update',
  del: '/t-vessels-info/delete',
}
const save = ref()
//分页器当前页码
let pageNo = ref<number>(1)
//每一页展示几条数据
let pageSize = ref<number>(10)
let total = ref<number>(0)
let list = ref([])
//控制抽屉显示与隐藏的字段
let drawer = ref<boolean>(false)
let skuInfo = ref<any>({})
//组件挂载完毕
onMounted(() => {
  getPage()
})

const query = reactive({
  recordFlag: '',
  consultProduct: '',
  consultantFirstName: '',
  consultantLastName: '',
  email: '',
  phoneNumber: '',
  handlePersonnel: '',
  consultDate_min: '',
  consultDate_max: '',
  handleDate_min: '',
  handleDate_max: '',
})

const range = ref([])
const change = (e) => {
  console.log(e);
  if (e && e.length) {
    query.consultDate_min = e[0]
    query.consultDate_max = e[1]
  } else {
    query.consultDate_min = ''
    query.consultDate_max = ''
  }
}
const range2 = ref([])
const change2 = (e) => {
  console.log(e);
  if (e && e.length) {
    query.handleDate_min = e[0]
    query.handleDate_max = e[1]
  } else {
    query.handleDate_min = ''
    query.handleDate_max = ''
  }
}

const search = () => {
  getPage(1)
}
const getPage = async (pager = 1) => {
  //当前分页器的页码
  pageNo.value = pager
  let { status, data, msg } = await seekGetPage({
    page: pageNo.value,
    limit: pageSize.value,
    ...query
  })
  if (status == 200) {
    let { records, total: tatalNums } = data
    total.value = tatalNums
    list.value = records
  } else {
    ElMessage({ type: 'error', message: msg })
  }
}
//分页器下拉菜单发生变化触发
const handler = (pageSizes: number) => {
  getPage()
}

const add = (row: any) => {
  save.value.show(row)
}

const handle = (row: any) => {
  save.value.show(row)
}

</script>

<style scoped>
.number {
  text-align: center;
}


.search {
  width: 100%;
  display: flex;
  align-items: center;
}
.inpt {
  width: 120px;
  margin-right: 10px;
}

.range {
  width: 250px;
  margin-right: 10px;
}
</style>
